package com.leetcode;

/**
 * TODO
 *
 * @author lefly
 * @version 1.0
 * @classname No154
 * @description
 * @date 2021/1/28 下午3:46
 */
public class No154 {
    public static void main(String[] args) {
        int[] nums = {2,2,2,0,1};
        int[] nums2 = {1,2,2,2,2,2,2};
        int min = findMin(nums2);
        System.out.println(min);
    }

    public static int findMin(int[] nums) {
        if(nums == null || nums.length < 1){
            return -1;
        }
        int len = nums.length;
        if(len == 1){
            return nums[0];
        }
        int left = 0,right = len - 1;
        while (left < right){
            int mid = left + (right - left) / 2;
            if (nums[mid] > nums[right]){
                left = mid + 1;
            }else if(nums[mid] < nums[right]){
                right = mid;
            }else{
                right--;
            }
        }
        return nums[left];
    }

}
